<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>MD5在线加密工具</title>
    <script src="../js/crypto-js.min.js"></script>
    <style>
        body {
            font-family: 'Arial', sans-serif;
            line-height: 1.6;
            margin: 0;
            padding: 20px;
            background-color: #fff;
            color: #333;
        }
        .container {
            max-width: 800px;
            margin: 0 auto;
            background-color: #fff;
            padding: 30px;
            border-radius: 8px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
        }
        .input-group {
            margin-bottom: 20px;
        }
        label {
            display: block;
            margin-bottom: 8px;
            font-weight: bold;
        }
        textarea, input[type="text"] {
            width: 100%;
            padding: 10px;
            border: 1px solid #ddd;
            border-radius: 4px;
            font-size: 16px;
            box-sizing: border-box;
        }
        textarea {
            height: 120px;
            resize: vertical;
        }
        .btn-group {
            display: flex;
            gap: 10px;
            margin-bottom: 20px;
        }
        button {
            padding: 10px 20px;
            color: white;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            font-size: 16px;
            flex: 1;
            transition: all 0.3s;
        }
        #encryptBtn {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        #encryptBtn:hover {
            opacity: 0.9;
            transform: translateY(-2px);
        }
        #clearBtn {
            background-color: #95a5a6;
        }
        #clearBtn:hover {
            background-color: #7f8c8d;
        }
        .result-container {
            margin-top: 20px;
        }
        .info {
            margin-top: 30px;
            padding: 15px;
            background-color: #f8f9fa;
            border-radius: 4px;
            font-size: 14px;
        }
        .info h3 {
            margin-top: 0;
            color: #2c3e50;
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="input-group">
            <label for="inputText">输入要加密的文本：</label>
            <textarea id="inputText" placeholder="请输入要加密的内容..."></textarea>
        </div>
        
        <div class="btn-group">
            <button id="encryptBtn">生成MD5</button>
            <button id="clearBtn">清空</button>
        </div>
        
        <div class="result-container">
            <div class="input-group">
                <label for="resultText32">32位MD5加密结果：</label>
                <input type="text" id="resultText32" readonly>
            </div>
            
            <div class="input-group">
                <label for="resultText16">16位MD5加密结果：</label>
                <input type="text" id="resultText16" readonly>
            </div>
        </div>
        
        <div class="info">
            <h3>关于MD5加密</h3>
            <p>MD5（Message-Digest Algorithm 5）是一种广泛使用的密码散列函数，由Ronald Rivest在1991年设计，可生成128位（16字节）的哈希值，通常表示为32位的十六进制数。</p>
        </div>
    </div>

    <script>
        document.getElementById('encryptBtn').addEventListener('click', function() {
            const inputText = document.getElementById('inputText').value.trim();
            if (!inputText) {
                alert('请输入要加密的内容！');
                return;
            }
            
            // 使用CryptoJS库生成MD5
            const md5Hash = CryptoJS.MD5(inputText).toString();
            
            document.getElementById('resultText32').value = md5Hash;
            document.getElementById('resultText16').value = md5Hash.substring(8, 24);
        });
        
        document.getElementById('clearBtn').addEventListener('click', function() {
            document.getElementById('inputText').value = '';
            document.getElementById('resultText16').value = '';
            document.getElementById('resultText32').value = '';
        });
    </script>
</body>
</html>